package com.fengxu.gmall.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.fengxu.gmall.bean.UserAddress;
import com.fengxu.gmall.service.OrderService;
import com.fengxu.gmall.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Reference()
    UserService userService;

    @HystrixCommand(fallbackMethod = "initOrderFallback")
    @Override
    public List<UserAddress> initOrder(String userId) {
        // 1.查询用户的收货地址
        List<UserAddress> addressList = userService.getUserAddressList(userId);
        // 遍历结果
        addressList.forEach(System.out::println);
        return addressList;
    }

    // initOrder调用失败后的处理方法
    public List<UserAddress> initOrderFallback(String userId) {
        return Arrays.asList();
    }
}
